package com.txzhang.springcloud.orderservice.config;

import com.alibaba.druid.pool.DruidDataSource;
import io.seata.rm.datasource.DataSourceProxy;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

@Configuration
public class DataSourceProxyAutoConfiguration {

    @Primary
    @Bean
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource druidDataSource() {
        DruidDataSource druidDataSource = new DruidDataSource();
        return druidDataSource;
    }
//
//    /**
//     * 配置数据源代理，用于事务回滚
//     *
//     * @return The default datasource
//     * @see DataSourceProxy
//     */
//    @Bean("dataSource")
//    public DataSource dataSource(DataSource druidDataSource) {
//       return new DataSourceProxy(druidDataSource);
//    }
}
